/**
 * 是否直接改写页面
 * @type {Boolean}
 */
var write = parseInt("{write}", 10);

/**
 * 加载广告素材
 * @param  {Object} target 添加区域
 */
function load(target) {
    var material = '<img src="{url}" style="display:block;width:100%;" />';
    if (write) {
        target.write(material);
    } else {
        target.innerHTML = material;
    }
}

/**
 * 检测当前环境，查找广告添加位置
 */
function check() {
    var target;
    var id = "${id}";
    if (write) {
        target = document;
    } else if (id){
        id = "#" + id;
        target = document.querySelector(id);
    }
    if (target) {
        load(target);
    } else {
        console.warn("Target area [#"+id+"] not founded.");
    }
}

check();
